﻿using System;
using System.Collections.Generic;
using Sklad1_2.Default;

namespace Sklad1_2.Add.Update
{
    public partial class UpdateProduct : Defaultform 
    {
        public UpdateProduct()
        {
            InitializeComponent();
        }

        public UpdateProduct(List<string> item):base(item)
        {
            InitializeComponent();
            ABase.AddItem(comboBox1,"angar");
            ABase.AddItem(comboBox2, "category");
            ABase.AddItemFirma(comboBox3,"firma");
            comboBox1.SelectedValue = item[1];
            comboBox2.SelectedValue = item[2];
            comboBox3.SelectedValue = item[3];
            textBox1.Text = item[4];
            textBox2.Text = item[5];
            textBox3.Text = item[6];
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string name = textBox1.Text,
                   price = textBox2.Text,
                   count = textBox3.Text,
                   sklad = Convert.ToString(comboBox1.SelectedValue),
                   category = Convert.ToString(comboBox2.SelectedValue),
                   firma = Convert.ToString(comboBox3.SelectedValue);
            if (textBox1.Text.Length>0&&textBox2.Text.Length>0&&textBox3.Text.Length>0)
            {
                for (int i = 0; i < price.Length; i++)
                {
                    if (price[i] == ',')
                    {
                        price = price.Replace(',', '.');
                    }
                }
                for (int i = 0; i < count.Length; i++)
                {
                    if (count[i] == ',')
                    {
                        count = count.Replace(',', '.');
                    }
                }
                for (int i = 0; i < name.Length; i++)
                {
                    if (name[i] == ',')
                    {
                        name = name.Replace(',', '.');
                    }
                }
                ABase.UpdateValueProduct(name,sklad,category,firma,price,count,id);
                Close();
            }
        }
    }
}
